<template>
  <div class="det_box">
    <navigate>文章详情</navigate>
    <div class="det_cont">
      <div class="head-det">
        <div class="det_info">
          <img :src="joinUrlImg(info.img)" alt="" class="det_img" />
          <div class="info_right">
            <div class="det_tit">{{ info.name }}</div>
            <div class="det_author">作者：{{ info.author }}</div>
            <div class="det_frequency">
              <img src="@/assets/images/function/hot_icon.png" alt="" />
              <span>阅读次数：{{ info.read_num }}次</span>
            </div>
          </div>
        </div>
        <div class="det_line"></div>
        <div class="det_label">
          <div class="label_txt">文章标签：</div>
          <div class="label_box">
            <div class="label_list">
              <div
                v-for="(item, index) in info.label"
                :key="index"
                class="item_label"
              >
                {{ item }}
              </div>
            </div>
            <div style="display: grid; justify-items: center">
              <img
                src="@/assets/images/function/collect.png"
                alt=""
                v-if="info.is_collect == 1"
                @click.stop="collectOperation(1)"
              />
              <img
                src="@/assets/images/function/no_collect.png"
                alt=""
                v-else
                @click.stop="collectOperation(0)"
              />
              <div>
                {{ info.is_collect == 1 ? "已收藏" : "未收藏" }}
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- 文章内容 -->
      <div class="article_cont">
        <div class="article_head">
          <div class="line"></div>
          <div class="tit">文章内容</div>
        </div>
        <div class="article_info">
          <div class="article_txt">
            {{ content }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { joinUrlImg } from "@/utils/setUrlImg";
import {
  queryArticleInfo,
  toCollect,
  toCancelCollect,
} from "@/api/funcation/mentalArticle";
export default {
  data() {
    return {
      info: {},
      content: "",
      formatDate: {},
    };
  },
  created() {
    this.formatDate = this.$route.query;
    this.getArticleInfo();
  },
  methods: {
    joinUrlImg,
    answerBack() {},
    //取消、收藏
    async collectOperation(val) {
      let id = this.info.id;
      if (val == 1) {
        await toCancelCollect({ id });
        this.$toast.success({ message: "取消收藏成功！" });
      } else {
        await toCollect({ id });
        this.$toast.success({ message: "收藏成功！" });
      }
      this.getArticleInfo();
    },
    async getArticleInfo() {
      let res = await queryArticleInfo({ id: this.formatDate.id });
      this.info = res.data.info;
      this.content = res.data.content;
    },
  },
};
</script>

<style lang="less" scoped>
.det_box {
  background-color: #f4f6fa;
  color: #333333;
}

.det_cont {
  margin: 10px 10px 0 10px;
}

.head-det {
  background: #ffffff;
  border-radius: 6.67px;
  padding: 16.67px 13.33px;
}

.info_right {
  flex: 1;
}

.det_info {
  display: flex;
  align-items: center;
}

.det_img {
  width: 55.67px;
  height: 80px;
  margin-right: 16.33px;
}

.det_tit {
  font-size: 20px;
  line-height: 20px;
  color: #000000;
}

.det_author {
  margin: 13px 0 10px;
}

.det_author,
.det_frequency {
  font-size: 12px;
  line-height: 12px;
  color: #555555;
}

.det_frequency img {
  width: 8.33px;
  height: 10.67px;
  margin-right: 7px;
}

.det_line {
  width: 100%;
  height: 0.33px;
  background: #aaaaaa;
  margin: 10px 0;
}

.det_label {
}

.label_box {
  display: flex;
  gap: 16px;
  align-items: center;
}

.label_txt,
.item_label,
.label_box {
  font-size: 12px;
  color: #aaaaaa;
  padding: 0 10.33px 0 3.33px;
}

.label_list {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12.67px 0 0;
  overflow: hidden;
}

.item_label {
  flex-shrink: 0;
  padding: 8px 12px;
  border: 0.33px solid rgba(51, 51, 51, 0.2);
  border-radius: 12px;
  padding: 6px 15px;
  color: #aaaaaa;
}

.label_box img {
  width: 23.33px;
  height: 23.33px;
  margin-bottom: 12.33px;
}

// /文章内容
.article_cont {
}

.article_head {
  display: flex;
  align-items: center;
  margin: 15.67px 0;
}

.article_head .line {
  width: 5.33px;
  height: 15.33px;
  background: linear-gradient(
      -10deg,
      rgba(255, 255, 255, 0.3) 0%,
      rgba(255, 255, 255, 0) 100%
    ),
    #2aa1ec;
  border-radius: 2.67px;
}

.article_head .tit {
  font-size: 15.33px;
  font-weight: bold;
  margin-left: 10px;
}

.article_info {
  padding: 10px;
  background: #ffffff;
  border-radius: 6.67px;
}

.article_tit {
  text-align: center;
  margin-bottom: 49px;
  font-size: 20px;
  line-height: 14px;
}

.article_txt {
  color: #555555;
  font-size: 14px;
  line-height: 28px;
  word-wrap: break-word;
  word-break: break-all;
}
</style>
